# writer:sp
# tiem: 2024/8/21 10:13
import os
'''分割路径，将路径分为目录和文件部分'''
# 分割路径
path = os.getcwd()
head, tail = os.path.split(path)
print("Head:", head)
print("Tail:", tail)
import os

# 示例路径
path1 = r'C:\Users\JohnDoe\Documents\Work\project.txt'
path2 = r'C:\Windows\System32'
path3 = r'file.txt'
#path4 = r'C:\Users\JohnDoe\'

# 分割路径
dir1, file1 = os.path.split(path1)
dir2, file2 = os.path.split(path2)
dir3, file3 = os.path.split(path3)
# dir4, file4 = os.path.split(path4)

# 打印结果
print("Path 1 directory part:", dir1)
print("Path 1 file part:", file1)
print("Path 2 directory part:", dir2)
print("Path 2 file part:", file2)
print("Path 3 directory part:", dir3)
print("Path 3 file part:", file3)
# print("Path 4 directory part:", dir4)
# print("Path 4 file part:", file4)
